import {searchPage, deleteById, searchColors,searchBrands,searchTypes} from '../../api/brand'
import {deleteProductById,addProduct,findbyid,searchGoodsVo,goodsCheckService,priceCheckVoService,add} from '../../api/product'
import pickerOptions from '@/utils/date';
// import {getBase64Str} from '../../utils/base64Utils'
// import base64 from '../../utils/getbase64Str2';


let priceadjust = {
    data() {
        return {
            //日期组件
            pickerOptions: pickerOptions,
            //table的list
            isshow:false,
            tableData: [],
            goodsData:[],
            goodsParams:{
                currentPage: 1,
                pageSize: 2
            },
            goodsTotal:0,
            total: 0,
            searchParams: {
                currentPage: 1,
                pageSize: 3
            },
            dialogVisible: false,
            look: false,
            dialogVisibleEdit: false,
            formData: {},
            formDataEdit: {},
            deleteForm:{},
            imageUrl: '',
            formLabelWidth: '120px',
            colorList: [],
            brandList: [],
            typeList: [],
            lookData:[],
            editData:{}
        };
    },
    methods: {
        //复选框的change事件，删除和修改拿到id
        checkBoxSelectionChange() {

        },
        currentPageChange(currentPage) {
            //console.log(currentPage);
            this.searchParams.currentPage = currentPage;
            this.findPage();
        },
        currentPageChange1(currentPage) {
            //console.log(currentPage);
            this.goodsParams.currentPage = currentPage;
            this.findGoods();
        },
        async findPage() {
            let response = await priceCheckVoService(this.searchParams);

            this.total = response.total;

            console.log(" response.data:", response.data);
            this.tableData = response.data;
        },
        async findGoods() {
            let response = await searchGoodsVo(this.goodsParams);

            this.goodsTotal = response.total;

            console.log(" goods.data:", response.data);
            console.log(" goodsparam.data:", this.goodsParams);
            this.goodsData = response.data;
        },
        resetGoodsForm() {
            this.goodsParams = {currentPage: 1, pageSize: 2};

            this.findGoods();
        },
        async init() {
            let response1 = await goodsCheckService();
            let response2 = await searchBrands();
            let response3 = await searchTypes();
            this.colorList = response1;
            this.brandList=response2;
            this.typeList=response3;
        },
        chooseTime() {
            this.searchParams.startTime = this.pickerOptions.startArrayDate[0];
            this.searchParams.endTime = this.pickerOptions.startArrayDate[1];
        },
        resetForm() {
            this.searchParams = {currentPage: 1, pageSize: 2};
            this.pickerOptions.startArrayDate = '';
            this.findPage();
        },
        //async表示异步调用 await：表示执行完这条语句，才执行下面语句
        async deleteById() {
            await deleteById(this.formData.id);
            this.findPage();
        },

        async deleteProductById() {
            await deleteProductById(this.deleteForm.productId);
            this.findPage();
        },
        getImgStr(e) {
            base64.getbase64Str(e.file).then(response => {
                this.formData.brandLogo = response;
                this.imageUrl = response;
            })

        },
        async addOrEdit() {
            await addProduct(this.formData);
            console.log("this.formData:",this.formData);
            this.formData={};
            this.findPage();
        },
        productEdit(){

        },
        editPrice(row){
            this.editData=row
        },
        initProduct(row){
            this.lookData=row;
            console.log("this.lookData：",this.lookData)
        },
        parseDateFull(time) {
            var x = new Date(time);
            var z = {
                y: x.getFullYear(),
                M: x.getMonth() + 1,
                d: x.getDate(),
                h: x.getHours(),
                m: x.getMinutes(),
                s: x.getSeconds(),
            };
            if (z.M < 10) {
                z.M = "0" + z.M;
            }
            if (z.d < 10) {
                z.d = "0" + z.d;
            }
            if (z.h < 10) {
                z.h = "0" + z.h;
            }
            if (z.m < 10) {
                z.m = "0" + z.m;
            }
            return z.y + "年" + z.M + "月" + z.d + "日";
        },
        addTypes(){
add(this.editData);
        }
    },
    created() {
        this.findPage();
        this.findGoods();
        this.init();
    }
};

export default priceadjust;